package com.atguigu.spzx.user.service.impl;

import com.atguigu.spzx.common.utils.AuthContextUtil;
import com.atguigu.spzx.common.utils.BeanUtils;
import com.atguigu.spzx.user.dto.UserAddressDetailsRespDto;
import com.atguigu.spzx.user.entity.UserAddress;
import com.atguigu.spzx.user.mapper.UserAddressMapper;
import com.atguigu.spzx.user.service.UserAddressService;
import com.atguigu.spzx.user.vo.UserAddressQueryRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * UserAddressServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2023/11/6
 */
@Service
public class UserAddressServiceImpl implements UserAddressService {

    @Autowired
    private UserAddressMapper userAddressMapper;

    /**
     * 获取用户地址列表
     * @return
     */
    @Override
    public List<UserAddressQueryRespVo> findUserAddressList() {
        Long userId = AuthContextUtil.getUserInfo().getId();
        List<UserAddress> userAddressList = userAddressMapper.getUserAddressListByUserId(userId);
        return BeanUtils.toBeanList(userAddressList,UserAddressQueryRespVo.class);
    }

    /**
     * 根据收货地址id获取收货地址
     * @param id
     * @return
     */
    @Override
    public UserAddressDetailsRespDto getUserAddressById(Long id) {
        UserAddress userAddress = userAddressMapper.selectById(id);
        return BeanUtils.toBean(userAddress,UserAddressDetailsRespDto.class);
    }
}
